{extend name="base" /}
{block name="body"}
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class=""><a href="{:url('/admin/gaode_agent')}">高德游戏</a></li>
            <li class="layui-this">编辑高德游戏</li>
        </ul>
        <div class="layui-tab-content">
            <form class="layui-form form-container" action="{:url('/admin/gaode_agent/update',['id'=>$gameagent['id']])}" method="post">
                <div class="layui-form-item">
                    <label class="layui-form-label">选择游戏</label>
                    <div class="layui-input-block">
                        <select name="gid" lay-search>
                            <option value="0">选择游戏</option>
                            {foreach name=":get_game_list()" item="vo"}
                                <option value="{$vo.id}" {if condition="$gameagent['gid']==$vo['id']"}selected{/if} >{$vo.name}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">选择渠道</label>
                    <div class="layui-input-block">
                        <select name="cid" lay-search>
                            <option value="0">选择渠道</option>
                            {foreach name=":get_channel_list()" item="vo"}
                                <option value="{$vo.id}"{if condition="$gameagent['cid']==$vo['id']"}selected{/if} >{$vo.platform}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">渠道分成（%）</label>
                    <div class="layui-input-block">
                        <input type="text" name="fencheng" value="{$gameagent.fencheng}" required  lay-verify="required" placeholder="CP分成" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">通道费（%）</label>
                    <div class="layui-input-block">
                        <input type="text" name="tongdao" value="{$gameagent.tongdao}" required  lay-verify="required" placeholder="通道费" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <input type="radio" name="status" value="0" title="关闭" {if condition="$gameagent.status==0"} checked="checked"{/if}>
                        <input type="radio" name="status" value="1" title="开启" {if condition="$gameagent.status==1"} checked="checked"{/if}>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="*">保存</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script>
layui.use('form', function(){
  var form = layui.form
   ,layer = layui.layer
  ,layedit = layui.layedit;
      laydate = layui.laydate;
	//时间选择器
	var start = laydate.render({
	                    elem: '#stime',
	                    type: 'datetime',
	                    format: 'yyyy-MM-dd HH:mm:ss',
	                    done: function(value, date, endDate) {
	                        start.config.max = {
	                            year: date.year,
	                            month: date.month - 1,
	                            date: date.date,
	                            hours: date.hours,
	                            minutes: date.minutes,
	                            seconds: date.seconds
	                        }
	                    }
	                });
	var end = laydate.render({
	                    elem: '#otime',
	                    type: 'datetime',
	                    format: 'yyyy-MM-dd HH:mm:ss',
	                    done: function(value, date, endDate) {
	                        start.config.max = {
	                            year: date.year,
	                            month: date.month - 1,
	                            date: date.date,
	                            hours: date.hours,
	                            minutes: date.minutes,
	                            seconds: date.seconds
	                        }
	                    }
	                });
    var apply = laydate.render({
        elem: '#atime',
        type: 'datetime',
        format: 'yyyy-MM-dd HH:mm:ss',
        done: function(value, date, endDate) {
            start.config.max = {
                year: date.year,
                month: date.month - 1,
                date: date.date,
                hours: date.hours,
                minutes: date.minutes,
                seconds: date.seconds
            }
        }
    });
	//监听指定开关
    form.on('radio(only)', function(data){
	    if (data.value == 1){
        $('#agent').attr("disabled",false);
        $("#agent").removeClass("layui-disabled");
		}else{
        $('#agent').attr("disabled",true);
        $("#agent").addClass("layui-disabled");
		}
    });
	
    //自定义验证规则
    form.verify({
      title: function(value){
        if(value.length < 2){
          return '游戏名称至少得2个字符啊';
        }
      }
	  ,agent: function(value){
	        if (value){
		    	if(!/[0-9]$/.test(value)){
		    	    return '代理ID必须为数字';
		    	}
		    }
	    }
	  ,datenow: function(value){
		    if(!/^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\s+(20|21|22|23|[0-1]\d):[0-5]\d:[0-5]\d$/.test(value)){
		        return '时间格式不正确<br>正确格式为: 2017-01-01 12:00:00 ';
		    }
	    }
    });
});
</script>
{/block}